package chzhenjia.learn.androidcode.dial;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import chzhenjia.learn.androidcode.R;

/**
 * 拨打电话的 Activity
 *
 * @author 陈圳佳
 *         日期:2015/7/13
 */
public class DialActivity extends AppCompatActivity {

    private View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.dial_btn_call:
                    call();
                    break;
            }
        }
    };
    private TextView etPhone;

    /**
     * 拨打电话的方法
     */
    private void call() {
        String number = etPhone.getText().toString();
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + number));
        startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dial);
        Button btnCall = (Button) findViewById(R.id.dial_btn_call);
        etPhone = (TextView) findViewById(R.id.dial_et_phone);

        btnCall.setOnClickListener(clickListener);
    }
}
